﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Enterprise.Service.User;
using Enterprise.Model.User;
namespace Enterprise.Test
{
    /// <summary>
    /// 人员应用服务测试
    /// </summary>
    [TestClass]
    public class TUserService
    {
        public TUserService()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，该上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        //
        // 编写测试时，可以使用以下附加特性:
        //
        // 在运行类中的第一个测试之前使用 ClassInitialize 运行代码
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // 在类中的所有测试都已运行之后使用 ClassCleanup 运行代码
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // 在运行每个测试之前，使用 TestInitialize 来运行代码
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // 在每个测试运行完之后，使用 TestCleanup 来运行代码
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        /// <summary>
        ///  人员新增测试
        /// </summary>
        [TestMethod]
        public void TestUserInsert()
        {
            UserEntity entity = new UserEntity();
            entity.UNAME = "许志华";
            entity.ULOGINNAME = "xzh";
            entity.ULOGINPASS = "000";
            entity.USEX = "男";
            entity.DEPTID = 0;
            entity.UADMIN = "0";
            entity.UIP = "10.66.237.109";
            entity.USTATUS = "0";
            entity.UORDERBY = 1;
            entity.DB_Option_Action = "Insert";
            UserService ser = new UserService();
            ser.UserExecute(entity);
            var q=ser.UserList().Where(p => p.UNAME == entity.UNAME).FirstOrDefault();
            Assert.AreEqual(entity.UNAME, q.UNAME);
        }

        /// <summary>
        ///  人员更新测试
        /// </summary>
        [TestMethod]
        public void TestUserUpdate()
        {
            UserService ser = new UserService();
            var entity = ser.UserList().FirstOrDefault();
            if (entity != null)
            {
                string s = Guid.NewGuid().ToString().Substring(0, 8);
                entity.UNAME = "许志华" + s;
                entity.ULOGINNAME = "xzh";
                entity.ULOGINPASS = "000";
                entity.USEX = "男";
                entity.DEPTID = 0;
                entity.UADMIN = "0";
                entity.UIP = "10.66.237.109";
                entity.USTATUS = "0";
                entity.UORDERBY = 1;
                entity.DB_Option_Action = "Update";
                ser.UserExecute(entity);
                var q = ser.UserList().Where(p => p.UNAME == entity.UNAME).FirstOrDefault();
                Assert.AreEqual(entity.UNAME, q.UNAME);
            }
        }

    }
}
